#include <iostream>
#include <memory>
using std::cout;
using std::endl;
using std::unique_ptr;
using std::shared_ptr;
class Point{
public:
    Point(int x, int y)
    :_x(x)
    ,_y(y)
    {

    }
    Point * Point_add(const Point * rhs){
        _x += rhs->_x;
        _y += rhs->_y;
        return this;
    }
private:
    int _x,_y;
};

void test(){
    //将裸指针直接给两个智能指针托管，导致double free
    int * p = new int(10);
    unique_ptr<int> up(p);
    unique_ptr<int> up2(p);
}

void test2(){
    shared_ptr<Point> up(new Point(1,2));
    //此时up2同样获得了up托管的指针,相当于两个指针托管了两个指针
    //但是由于没有通过拷贝构造函数，因此两个指针的引用计数均为1,发生double free
    shared_ptr<Point> up2(up->Point_add(new Point(3,4)));
}

int main()
{
    test2();
    return 0;
}

